<template>
    <div>
        <attribute-tabs :title="widgetTitle">
            <div slot="content">
                <el-form ref="form" label-width="80px" size="small" label-position="left">
                    <slot name="content-des">
                        <attribute-item title="组件名称及描述">
                                <el-form-item label="标题名称">
                                    <el-input
                                        v-model="content.text"
                                        maxlength="8"
                                        show-word-limit
                                        placeholder="请输入标题名称"
                                    ></el-input>
                                </el-form-item>
                                <el-form-item label="标题图标">
                                    <material-select
                                        class="m-r-10"
                                        ref="materialSelect"
                                        v-model="content.icon"
                                        :size="60"
                                        upload-bg="#fff"
                                        :enable-domain="false"
                                    >
                                        <i class="el-icon-plus lg"></i>
                                    </material-select>
                                </el-form-item>
                                <el-form-item label="标识字段">
                                    <WidgetName></WidgetName>
                                </el-form-item>
                                <el-form-item label="权限">
                                    <el-checkbox-group v-model="operate">
                                        <el-checkbox label="delete">删除组件</el-checkbox>
                                        <el-checkbox label="copy">复制组件</el-checkbox>
                                        <el-checkbox label="moveup">上移组件</el-checkbox>
                                        <el-checkbox label="movedown">下移组件</el-checkbox>
                                    </el-checkbox-group>
                                </el-form-item>
                        </attribute-item>
                    </slot>
                    <slot name="content-nav">
                        <attribute-item title="导航内容">
                            <nav-list v-model="content.data" @add="addContentData" />
                        </attribute-item>
                    </slot>
                </el-form>
                <slot name="sub-content"></slot>
            </div>
            <div slot="styles">
                <el-form ref="form" label-width="80px" size="small" label-position="left">
                    <slot name="styles-color">
                        <attribute-item title="颜色设置">
                            <el-form-item label="底部背景">
                                <color-select v-model="styles.root_bg_color" reset-color="" />
                            </el-form-item>
                            <el-form-item label="组件背景">
                                <color-select v-model="styles.bg_color" reset-color="#FFFFFF" />
                            </el-form-item>
                            <el-form-item label="分割线颜色">
                                <color-select v-model="styles.divider_color" reset-color="#DDDDDD" />
                            </el-form-item>
                            <el-form-item label="字体颜色">
                                <color-select v-model="styles.font_color" reset-color="#626262" />
                            </el-form-item>
                        </attribute-item>
                    </slot>
                    <slot name="styles-padding">
                        <attribute-item title="内边距设置">
                            <el-form-item label="上边距">
                                <slider v-model="styles.padding_top" />
                            </el-form-item>
                            <el-form-item label="下边距">
                                <slider v-model="styles.padding_bottom" />
                            </el-form-item>
                            <el-form-item label="左右边距">
                                <slider v-model="styles.padding_horizontal" />
                            </el-form-item>
                        </attribute-item>
                    </slot>

                    <slot name="styles-margin">
                    
                        <attribute-item title="外边距设置">
                            <el-form-item label="上边距">
                                <slider v-model="styles.margin_top" />
                            </el-form-item>
                            <el-form-item label="下边距">
                                <slider v-model="styles.margin_bottom" />
                            </el-form-item>
                            <el-form-item label="左右边距">
                                <slider v-model="styles.margin_horizontal" />
                            </el-form-item>
                        </attribute-item>
                    </slot>

                    <slot name="radius">
                        <attribute-item title="圆角设置">
                            <el-form-item label="上圆角">
                                <slider v-model="styles.border_radius_top" />
                            </el-form-item>
                            <el-form-item label="下圆角">
                                <slider v-model="styles.border_radius_bottom" />
                            </el-form-item>
                        </attribute-item>
                    </slot>
                </el-form>
                <slot name="sub-styles"></slot>
            </div>
        

            <!-- <template v-if="$slots.other"> -->
            <div slot="other" >
                <slot name="other"></slot>
            </div>
                <!-- <slot name="other"></slot> -->
                
            <!-- </template> -->
            
        </attribute-tabs>
    </div>
</template>

<script lang="ts">
import { Component, Prop, Vue } from 'vue-property-decorator'
import { Getter } from "vuex-class"
import AttributeTabs from '@/components/decorate/attribute-tabs.vue'
import ColorSelect from '@/components/decorate/color-select.vue'
import StyleChose from '@/components/decorate/style-chose.vue'
import Slider from '@/components/decorate/slider.vue'
import AttributeItem from '@/components/decorate/attribute-item.vue'
import MaterialSelect from '@/components/material-select/index.vue'
import NavList from '@/components/decorate/nav-list.vue'
// src\components\decorate\WidgetName.vue
import WidgetName from '@/components/decorate/WidgetName.vue'
import widgets from '@/components/decorate/widgets'
import pcWidgets from '@/components/decorate/pc-widgets'
@Component({
    components: {
        AttributeTabs,
        ColorSelect,
        StyleChose,
        Slider,
        AttributeItem,
        MaterialSelect,
        NavList,
        WidgetName
    }
})
export default class AttributeCom extends Vue {
    @Prop({ default: 'mobile' }) client!: string
    @Getter('widgetTitle') widgetTitle!: string
    localWidgetName: string = ''
    widgets = this.client == 'mobile' ? widgets : pcWidgets

    operates = []

    /** S data **/

    /** E data **/

    /** S computed **/

    get content() {
        return this.$store.getters.content
    }

    set content(val) {
        const data = {
            key: 'content',
            value: val
        }
        
        this.$store.commit('setAttribute', data)
    }
    get contentData() {
        return this.$store.getters.content.data || []
    }
    set contentData(val) {
        const localContent = Object.assign({}, JSON.parse(JSON.stringify(this.content)), {
            data: val
        })
        const data = {
            key: 'content',
            value: localContent
        }
        
        this.$store.commit('setAttribute', data)
    }
    get styles() {
        return this.$store.getters.styles
    }

    get widgetName() {
        return this.$store.getters.widgetName
    }
    
    get operate() {
        return this.$store.getters.operate
    }

    set operate(data) {
        // setPageDataOperate
        this.$store.commit('setPageDataOperate', data)
    }
    /** E computed **/

   

    mounted(){
        this.localWidgetName = this.widgetName
        // this.operates = this.$store.
    }

    

    /** S methods **/
    async updateWidgeteName () {
        try {
            await this.$confirm('是否确认更改需要显示的组件?', '警告', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            })
            // @ts-expect-error
            const hasComponent = !!this.widgets[this.localWidgetName]
            if (hasComponent) {
                this.setPageDataName()
                return
            } 
            await this.$confirm('代码中没有对应组件，是否继续?此操作完成后，请立即在代码中添加对应组件', '警告', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            })
            this.setPageDataName()
            
        } catch (error) {
            this.$message({
                type: 'info',
                message: '已取消删除'
            })
        }
        
    }
    setPageDataName() {
        this.$store.commit('setPageDataName', this.localWidgetName)
    }

    addContentData(v:[]) {
        const data = {
            key: 'content',
            value: {
                ...this.content,
                data: v
            }
        }
        
        this.$store.commit('setAttribute', data)
    }

    /** E methods **/


}
</script>

<style lang="scss" scoped></style>
